package org.home.sys.controller;

import org.home.util.FileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by nanshouxiao on 2017/7/31 15:40.
 */
@Controller
@RequestMapping("file")
public class FileController {

    @RequestMapping("uploadFile")
    public void uploadFile(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
        String filePath = "E:\\test";
        try {
            FileUtils.writeByteToFile(filePath, file.getInputStream(), false);
            System.out.println("用户" + request.getParameter("userName") + " 上传文件成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
